package com.panshi.admin_manage.controller;

import com.panshi.admin_manage.service.IZxService;
import com.panshi.vo.ArticleT;
import com.panshi.vo.DataResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@CrossOrigin
//@RequestMapping(produces = {"application/json;charset=UTF-8"})
public class ZxController {

    @Resource
    private IZxService zxService;

    @GetMapping("/zx-app/list")
    public DataResult findArticle(){
        DataResult dataResult = new DataResult();
        dataResult.setData(zxService.list(null));
        return dataResult;
    }

    @GetMapping("/zx-app/byid/{id}")
    public ArticleT getZxbyId(@PathVariable("id") Integer id){
        ArticleT article = zxService.getById(id);
        return zxService.getById(id);
    }

    @PostMapping("/zx-app/add")
    public Boolean add(@Validated ArticleT articleT){
        return zxService.save(articleT);
    }

    @GetMapping("/zx-app/del/{id}")
    public Boolean del(@PathVariable("id") Integer id){
        ArticleT articleT = new ArticleT();
        articleT.setId(id);
        articleT.setAState(-1);
        return zxService.updateById(articleT);
    }

    @PostMapping("/zx-app/upd")
    public Boolean upd(@Validated ArticleT articleT){
        System.out.println("-------------------------------------------------------------------");
        System.out.println(articleT);
        return zxService.updateById(articleT);
    }

}
